package com.hcb.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.hcb.adapter.AdapterAddContacts.viewHolder;
import com.hcb.app911.R;
import com.hcb.dto.ContactsDTO;
import com.hcb.dto.ResponderDTO;

public class AdapterListSearchResponder extends ArrayAdapter<Object> {
	Context mContext;
	private ArrayList<Object> arrObject;

	public AdapterListSearchResponder(Context context, int resource,
			ArrayList<Object> arr) {
		super(context, resource, arr);
		mContext = context;
		setArrObject(arr);
	}

	class viewHolder {
		TextView txtnametype, txtstreetname, txttownstate, txtphonenumber,
				txttime;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return getArrObject().size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return getArrObject().get(position);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);


		 View rowView = inflater.inflate(R.layout.adapter_list_search_reponder, parent,
				false);

		viewHolder holder = new viewHolder();

		// holder.icon = (ImageView) rowView.findViewById(R.id.icon);
		holder.txtnametype = (TextView) rowView
				.findViewById(R.id.txtnametype);
		holder.txtstreetname = (TextView) rowView
				.findViewById(R.id.txtstreetname);
		holder.txttownstate = (TextView) rowView
				.findViewById(R.id.txttownstate);
		holder.txtphonenumber = (TextView) rowView
				.findViewById(R.id.txtphonenumber);
		holder.txttime = (TextView) rowView
				.findViewById(R.id.txttime);

		ResponderDTO dto = (ResponderDTO) getArrObject().get(position);
		// holder.icon.setImageResource(dto.getImg());
		holder.txtnametype.setText(dto.getResponder_name());
		holder.txtstreetname.setText(dto.getTown());
		holder.txttownstate.setText(dto.getTown() +", "+ dto.getState());
		holder.txtphonenumber.setText(dto.getContact_number_one());
		holder.txttime.setText(dto.getAdded_on());

		return rowView;
	}

	public ArrayList<Object> getArrObject() {
		return arrObject;
	}

	public void setArrObject(ArrayList<Object> arrObject) {
		this.arrObject = arrObject;
	}
}
